package com.itheima.userdemo.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

// /*拦截所有的请求
// *.jsp 拦截所有后缀是.jsp
//@WebFilter("/*")
public class FilterDemo2 implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("--FilterDemo2-init,初始化，执行1次");
    }
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("---FilterDemo2-doFilter...start,只要符合规则就执行");
        // 放行之前的逻辑
        chain.doFilter(request,response);
        // 放行之后（响应给前端）逻辑
        System.out.println("---FilterDemo2-doFilter...end");
    }

    @Override
    public void destroy() {
        System.out.println("--FilterDemo2-destroy... 销毁，服务器重启或销毁，才执行");
    }
}
